package com.example.leetcode;

/**
 * 动态规划  & 递归
 * F(0) = 0，F(1) = 1
 * F(n) = F(n - 1) + F(n - 2)，其中 n > 1
 */
public class Demo0503 {

    public static void main(String[] args) {

    }

    //递归
    public static int fib(int n) {
        if (n<=1){
            return n;
        }
        return fib(n-1)+fib(n-2);
    }

    //动态规划
    public static int fib2(int n) {
        if (n<=1){
            return n;
        }
        int [] fun=new int[n+1];
        fun[0]=0;
        fun[1]=1;
        for (int i = 2; i < n+1; i++) {
            fun[i]=fun[i-1]+fun[i-2];
        }
        return fun[n];
    }
}
